<?php

/** 
* 
* 
* by:南宁火蝶科技有限公司 http:///www.HdsysCms.com
* 声明:本系统禁止用二次开发、侵犯HdsysCms著作和除去HdsysCms进行售卖,如发现将追究一切权利,模版制作属于自己所得可以通过本系统对外开发模版获取收益!
* 
* 2019年第一版本发布 - 到2023.9.1开源使用! 
* php混淆工具:phpencry.wbox.top
* 
* 注意防骗:@HdsysCms 官方没授权任何个人机构合作,唯一收款抬头:《南宁火蝶科技有限公司》和官网显示客服唯一渠道客服,其它渠道以HdsysCms名义行为均骗子!
*
*/
	

defined('HDSYS_SET') or die("" . 'Not,This File Not Can in Ie Open');
function _sqliteRegexp($param_string, $param_pattern)
{
if ($param_pattern==$param_string) {
return true;
}
if ($param_pattern=='' or $param_string=='') {
return false;
}
if (strlen($param_pattern) > 100) {
return false;
}
$param_pos1=strpos($param_string, '|');
if ($param_pos1 > 0) {
if (preg_match('/^' . $param_string . '$/i', $param_pattern)) {
return true;
}
} else {
$param_pos1=strpos($param_pattern, $param_string);
if ($param_pos1 > -1) {
return true;
}
}
return false;
}
class sqlite
{
public $intelligence_connection;
public $intelligence_exsql;
public function __construct()
{
$param_val_file=HDSYS_DIR_DATA . DBSQLITEFILE;
$this->intelligence_connection=new SQLite3($param_val_file);
if ($this->intelligence_connection->createFunction("regexp", "_sqliteRegexp", 2)===FALSE)
exit("Failed regexp function");
}
public function __destruct()
{
$this->intelligence_connection=null;
}
public function intelligence_fetch($param_sth)
{
$param_data=$param_sth->fetchArray(SQLITE3_ASSOC);
return $param_data;
}
public function intelligence_sql()
{
return $this->intelligence_exsql;
}
public function intelligence_query($param_val_sql)
{
$param_val_sql=call_my_str_replace('RAND()', 'RANDOM()', $param_val_sql);
$this->intelligence_exsql=$param_val_sql;
$param_mysql_res=$this->intelligence_connection->query($this->intelligence_exsql);
if ($param_mysql_res) {
return $param_mysql_res;
} else {
$this->intelligence_SQLaddlog($param_val_sql . "\nerror:" . $this->intelligence_connection->lastErrorMsg());
if ($this->intelligence_connection->lastErrorMsg()=='attempt to write a readonly database') {
bs_lib::Alerts('权限错误', '数据库没有写入权限,请确保Data目录有写入权限.');
}
return false;
}
}
public function intelligence_SQLaddlog($param_val_sql)
{
$param_name=HDSYS_DIR_SYS . 'Data/log/mysql_db.php';
if (@call_my_file_exists($param_name)) {
} else {
@call_my_file_put_contents($param_name, '<?php exit; ?>');
}
$param_handle=@fopen($param_name, 'a');
if (!$param_handle) {
return false;
}
if (@fwrite($param_handle, "<?php exit; ?>\n" . $param_val_sql . "\n")===false) {
return false;
}
@fclose($param_handle);
return true;
}
public function intelligence_getlist($param_val_sql)
{
$param_recordlist=array();
foreach ($this->intelligence_query($param_val_sql) as $param_rstmp) {
$param_recordlist[]=$param_rstmp;
}
return $param_recordlist;
}
public function intelligence_array($param_val_sql)
{
$param_tmp=$this->intelligence_query($param_val_sql);
if (!$param_tmp) {
return false;
}
try {
$param_data=$param_tmp->fetchArray(SQLITE3_ASSOC);
} catch (PDOException $e) {
exit('error:' . $param_val_sql);
}
return $param_data;
}
public function intelligence_is_table($param_table)
{
$param_sql="SELECT COUNT(*) as CNT FROM sqlite_master where type='table' and name='{$param_table}'";
$param_tmp=$this->intelligence_query($param_sql);
if (!$param_tmp) {
return 0;
}
$param_arr=$param_tmp->fetchArray(SQLITE3_ASSOC);
if (isset($param_arr['CNT'])) {
return $param_arr['CNT'];
} else {
return 0;
}
}
public function intelligence_intelligence_getinsert_id()
{
return $this->intelligence_connection->lastInsertRowID();
}
}
